package com.thinkcube.edutainment;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

public class ReachabilityTest {
	public interface Callback {
		void onReachabilityTestPassed();

		void onReachabilityTestFailed();
	}

	private Context mContext;

	private Callback mCallback;

	public ReachabilityTest(Context context, Callback callback) {

		mContext = context;

		mCallback = callback;
		isConnected(mContext);
	}

	private void isConnected(Context context) {

		if (context != null) {
			ConnectivityManager manager = (ConnectivityManager) context
					.getSystemService(context.CONNECTIVITY_SERVICE);
			NetworkInfo networkInfo = manager.getActiveNetworkInfo();
			if (networkInfo != null && networkInfo.isConnected()) {
				mCallback.onReachabilityTestPassed();
			} else {
				mCallback.onReachabilityTestFailed();
			}
		}
		else{
			mCallback.onReachabilityTestPassed();
		}

	}
}
